/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ling
 * Date: 2022-05-12
 * Time: 18:25
 */
public class MyQueue {
    class Node{
        int val;
        Node next;
        public Node(int val){
            this.val=val;
        }
    }
    Node head;
    Node last;

    public void offer(int val){
        Node node=new Node(val);
        if(this.head==null){
            head=node;
            last=node;
        }else{
            last.next=node;
            last=node;
        }

    }
    public boolean isEmpty(){
        if(head==null)
            return true;
        else
            return false;
    }
    public int poll(){
        if(isEmpty()){
            throw new RuntimeException("队列为空");
        }
        int tmp=head.val;
        head=head.next;
        if(head==null){
            last=null;
        }
        return tmp;
    }
    public int size(){
        Node cur=head;
        int count=0;
        while(cur!=null){
            count++;
            cur=cur.next;
        }
        return count;
    }
    public int peek(){
        if(isEmpty()){
            throw new RuntimeException("队列为空");
        }
        return head.val;
    }
}
